function calcTotalAmount() {
  var val1 = $('#total').text()
  var val2 = $('#fee').text()

  val1 = new BigNumber(val1)
  val2 = new BigNumber(val2)
  // console.log("---------------")
  var sum = val1.plus(val2)
  // console.log(sum)
  var fee = $('#fee-rate').text()
  // console.log(fee)
  fee = new BigNumber($('#fee-rate').text()).dividedBy('100').toFormat()
  // console.log(fee)
  sum = sum.plus(new BigNumber(val1.multipliedBy(fee)))
  // console.log(sum)
  $('#sum').text(sum.toFormat())

}

function getTotalAmount(account) {
  $.ajax({
    url: ajaxWebsite + 'Home/Ytc/getAccount',
    type: 'POST',
    data: {
      account: account
    },
    success: function (res) {
      // console.log(res[0])
      var money = new BigNumber(res)
      var y = Math.pow(10, 18)
      money = money.dividedBy(y).toFormat(16)
      $('#t_amount').text(money)
    }
  })
}

function getFreezeAmount(account) {
  $.ajax({
    url: ajaxWebsite + 'Home/Ytc/getFreeze',
    type: 'POST',
    data: {
      account: account
    },
    success: function (res) {
      $('#freeze_amount').text(res)
    }
  })
}

function ytcTrade() {
  var from = $('#from').val()
  var to = $('#to').val()
  // var fee = $('#fee').text()
  var amount = $('#sum').text()

  amount = new BigNumber(amount.replace(',', ''))
  // var fee = new BigNumber(amount.multipliedBy('0.001'))
  // fee = new BigNumber(fee).toFixed()
  // .multipliedBy(Math.pow(10, 18))
  // var sum = amount.toNumber()'
  // var fee = 0.001
  var amount = new BigNumber(amount).toFixed()
  // console.log(fee)
  // console.log(amount)
  $.ajax({
    url: ajaxWebsite + 'Home/Ytc/ytcTrade',
    type: 'POST',
    data: {
      from: from,
      to: to,
      amount: amount,
      // fee: fee
    },
    success: function (res) {
      if (res === 0) {
        addToast('发送失败', '地址有误，请重新输入', 'error')
      } else {
        addToast('发送成功', '两个地址 交易成功', 'notice')
        console.log(res)
      }
    },
    error: function (err) {}
  })
}

$('#amount').bind('input keyup', function () {
  calcTotalAmount()
})